import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '../store/user'
import { useGlobalMessage } from '../utils/message'

const routes = [
  {
    name:'home',
    path: '/',
    component: () => import('../views/Home.vue')
  },
  {
    name:'arbitration',
    path: '/arbitration',
    component: () => import('../views/Arbitration.vue'),
    meta: { requiresAuth: true }
  },
  {
    name:'arbitrationResult',
    path: '/arbitrationResult',
    component: () => import('../views/ArbitrationResult.vue'),
    meta: { requiresAuth: true }
  },
  {
    name:'paymentid',
    path: '/payment/:id',
    component: () => import('../views/Payment.vue'),
    meta: { requiresAuth: true }
  }
  // ,
  // {
  //   name:'member',
  //   path: '/member',
  //   component: () => import('../views/Member.vue'),
  //   meta: { requiresAuth: true }
  // }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  const userStore = useUserStore()
  const message = useGlobalMessage()
  
  // if (to.meta.requiresAuth && !userStore.isLoggedIn) {
  //   message.warning('请先登录')
  //   next('/')
  // } else {
  //   next()
  // }
  next()
})

export default router
